//#pragma once
#include"graphics.h"

//**************************************主菜单
extern WINDOW* g_win;
extern GRAPHICS_COLOR g_fore_color;
extern GRAPHICS_COLOR g_back_color;
extern int g_style;
extern int arr_cursor_num;
POINT* head = NULL;
POINT* old_head=NULL;
void drawMenu();		//画出菜单
int judge_dsphead=0;
int count=0;
void menu()				
{
	head = (POINT* ) malloc(sizeof(POINT) );//棋子的栈头;
	head->next = NULL;
	int tmp;
	int getc;
	tmp = 1;			//指向菜单第几行
	drawMenu(g_win,tmp);		//初始化菜单
	while(1)
	{
		drawMenu(g_win,tmp);	
		getc = readkey();		//读取键盘光标上下移动

		if(tmp == 1 && getc == SPACE) 	 //人人对战
		{ 
                     
                     dsphead();
                     judge_dsphead=1;
                     arr_cursor_num=tmp;
			manAndMan();
			continue;
		}
		else if(tmp == 2 && getc == SPACE)  //人机对战
		{
                     dsphead();
                     judge_dsphead=2;
			arr_cursor_num=tmp;
                     manAndComputer();
			continue;
		}
		else if(tmp == 4 && getc == SPACE)  //棋盘重现
		{
                     if(head!=NULL)
			   ChessDisplay();
			continue;
		}
               /*
		else if(tmp == 4 && getc == SPACE)  //建立主机
		{
		}
		else if(tmp == 5 && getc == SPACE)  //加入网战
		{
		}
               */
		else if(tmp == 3 && getc == SPACE)  //继续游戏
		{
                     if(arr_cursor_num==1)
                           GOON_mm();
                     else if(arr_cursor_num==2)
			      GOON();

			continue;
		}
              else if(tmp==5 && getc== SPACE)
                {
                }
		else if(tmp == 6 && getc == SPACE)  //退出
		{
			return;
		}
			
		switch(getc)
		{
			case KEYDOWN:
				if(tmp != 6)
					tmp += 1;
				else
					tmp = 1;	
				break;
			case KEYUP:  
				if(tmp != 1)
					tmp -= 1;
				else
					tmp = 6;
				break;
		}
		//drawMenu(g_win,tmp);	
	}			
}


void drawMenu(WINDOW* g_win, int tmp)
{
	g_fore_color = GCRed;			//初始化前景色
	g_back_color = GCBlack;			//初始化背景色
	wattrset(g_win,CURRENT_ATTRIBUTE);		//更新前景色和背景色
	char* p[] = {"1.人人对战","2.人机对战",/*"4.建立主机","5.加入网战",*/"3.继续游戏","4.棋盘重现","5.帮    助","6.退    出"};
	int i;
	//sleep(3);//test
	clear_screen(0,0,COLS,LINES);		//COLS，LINES是库函数中的宏
	for(i=10; i<16; i++)
		mvaddstr(i, 75, p[i-10]);
	
	
	mvaddstr(0,18,"************上下操作，空格选择*************");//提示操作
	wrefresh(g_win);


	g_fore_color = GCYellow;			//设置前景色
	g_back_color = GCBlue;			//设置背景色
	wattrset(g_win,CURRENT_ATTRIBUTE);		//更新前景色和背景色
	mvaddstr(tmp+9,75,p[tmp-1]);		//当前选框更改颜色覆盖之前的   ....................
	
	char* ptr2 ="欢乐五子棋";
	mvaddstr(3,33,ptr2);				//标题
	
	drawChessboard();
	
	g_back_color = GCWhite;			//设置背景色
	wattrset(g_win,CURRENT_ATTRIBUTE);		//更新前景色和背景色
	char* ptr1 = "                                                                          ";	

	mvaddstr(2,0,ptr1);				//清除上面的提示
	
	wrefresh(g_win);				//刷新窗口，显示窗口的最新变化
		
}

void dsphead()
{
   if(0==judge_dsphead || old_head==NULL)
         return ;
   POINT* tmp = old_head->next;
   while(tmp != NULL)	//释放栈
    {	
      POINT* tmp1=tmp->next;
      free(tmp);
      tmp = tmp1;
   }
   old_head=NULL;
   judge_dsphead=0;	
   count=0;

}

